﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EasyMvcBlog.Filter
{
    public class AuthorizationAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            string controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
            string action = filterContext.ActionDescriptor.ActionName.ToLower();

            //检查是否登录
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                //跳转到登录页面
                filterContext.HttpContext.Response.Redirect("~/home/login");
                //阻止执行相应的action
                filterContext.Result = new EmptyResult();
            }
        }

    }

}